
/**
 * Module dependencies.
 */

var express = require('express');
var routes = require('./routes');
var user = require('./routes/user');
var http = require('http');
var path = require('path');

var app = express();

var io = require('socket.io')
var RedisStore = require('connect-redis')(express);
var COOKIE_SECRET = 'very secret string';
var cookieParser = express.cookieParser(COOKIE_SECRET);
var sessionStore =  new RedisStore({
    host: '127.0.0.1',
    port: 6379,
    ttl: 30,
    prefix: 'settings.redisPrefix',
    db: 'mydb'})
var EXPRESS_SID_KEY = 'express.sid';
var SECRET=COOKIE_SECRET


// all environments
app.set('port', process.env.PORT || 4000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(cookieParser);
app.use(express.session({
    store: sessionStore,
    secret: SECRET ,
    cookie: {
        httpOnly: true
    },
    key: EXPRESS_SID_KEY
}));
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

app.get('/', function (req, res) {
    res.redirect('login.html');
});

// Very basic login/logout routes
app.get('/login', function (req, res) {
    // We just set a session value indicating that the user is logged in
    var uname = req.param("uname")
    var group = req.param("group")
    req.session.mainInfo = {uname:uname,group:group,uid:group,itsc_id:group};
    res.redirect('http://127.0.0.1:4000/index.html');
});

http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});
